Skip to main content

Vec module (vec)

Start here

vec::Vec is a dynamic list — one container, many types. Push a number, then a string, then a decimal into the same list. Write bring vec, then new vec::Vec(). The runtime manages the storage; you never touch raw memory.

A tiny program

bring vec

var list: vec::Vec = new vec::Vec()
list.push(10)
list.push("FlowWing")
list.push(3.14159)
println(list.size())
println(list.get(0))
list.set(0, 99)
println(list.get(0))
list.removeAt(1)

Output:

3
10
99

Typical uses: building lists on the fly (push / pop), looking up by index (get / set), and occasionally sorting or reversing.

Common operations (cheat sheet)

  • Grow & shrinkpush, pop, insert, removeAt
  • Accessget, set, size, isEmpty
  • Utilityclear, indexOf, sort(ascending: bool), reverse()
  • You can chain calls in many styles the same as with other class APIs.

Iteration

Loop over elements with size() and get() in a for-loop:

bring vec

var list: vec::Vec = new vec::Vec()
list.push(10)
list.push(20)
list.push(30)

for (var i: int = 0 to list.size() - 1 : 1) {
  println("list[", i, "] = ", list.get(i))
}

Output:

list[0] = 10
list[1] = 20
list[2] = 30

Performance

OperationComplexity
push()O(1) amortized
pop()O(1)
get()O(1)
set()O(1)
insert()O(n)
removeAt()O(n)
indexOf()O(n)
size()O(1)

More detail: API and behavior

The public surface is the vec::Vec class. Vec holds values of any type — one Vec mixes element types freely, unlike fixed T[n] arrays.

Source & tests (if you have the repository)

WhatWhere
Module source (reference)fw-modules/vec_module/vec-module.fg in the Flow-Wing repository.
Integration-style fixturestests/fixtures/LatestTests/VecModuleTests/ — how bring vec, method calls, and edge cases are exercised in the project's tests.

Cloning the repo is not required to use vec::Vec. Those paths are for people reading or contributing to the compiler.